<?php
/**
 * 生成随机数
 * @param $length 随机数长度
 * @return null|string
 */
function getRandChar($length){
    $str = null;
    $strPol = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $max = strlen($strPol) - 1;
    for($i = 0;$i < $length; $i++){
        $str .= $strPol[rand(0,$max)];
    }
    return $str;
}

function http_curl($url,$data =array(),$method ="get",$returnType ="json")
{
    //1.开启会话
    $ch = curl_init();
    //2.设置参数

    curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    if($method!="get"){
        curl_setopt($ch,CURLOPT_POST,TRUE);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
    }
    curl_setopt($ch,CURLOPT_URL,$url);
    //执行会话
    $json = curl_exec($ch);
    curl_close($ch);
    if($returnType == "json"){
        return json_decode($json,true);
    }
    return $json;
}

/**
 * 统一返回信息
 * @param $code
 * @param $data
 * @param $msge
 */
function msg($code, $data, $msg)
{
    return compact('code', 'data', 'msg');
}